package com.chris.cc.user.service.wrapper;

import com.chris.cc.common.exception.InvalidArgumentException;
import com.chris.cc.user.model.dto.DeptDto;
import com.chris.cc.user.model.vo.DeptVO;
import com.chris.cc.user.service.DeptService;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * Copyright (c) 2018-2025, chris All rights reserved.
 * <p>
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * <p>
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * <p>
 * Author: haoka (haokang207@126.com)
 * <p>
 * Date: 2018/8/24 10:27
 * <p>部门|公司增删改查</p>
 **/
@Service
public class DeptServiceWrapper {
    @Autowired
    private DeptService deptService;

    /**
     * 新增：name、address、contact、tel
     *
     * @param dept
     * @throws InvalidArgumentException
     */
    public void add(@NonNull DeptDto dept) throws InvalidArgumentException {
        deptService.add(dept);
    }

    /**
     * 查询列表
     *
     * @param enable
     * @param keyword
     * @param page
     * @return
     */
    public Page<DeptVO> query(Boolean enable, String keyword, @NonNull Pageable page) {
        return deptService.query(enable, keyword, page).map(DeptVO::from);
    }

    /**
     * 启用|禁用
     *
     * @param id
     * @param enable
     */

    public void toggle(@NonNull Long id, Boolean enable) {
        deptService.toggle(id, enable);
    }

    /**
     * 更新：name、address、contact、tel
     *
     * @param dept
     * @throws InvalidArgumentException
     */
    public void update(@NonNull DeptDto dept) throws InvalidArgumentException {
        deptService.update(dept);
    }

    /**
     * 获取
     *
     * @param deptId
     * @return
     */
    public DeptVO get(@NonNull Long deptId) {
        return DeptVO.from(deptService.get(deptId));
    }
}
